package com.xiaode.controller.admin.happy;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Ret;
import com.xiaode.common.anotation.Authority;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;

@Path("/aHappy")
@Api("乐学园后台相关服务")
@EnableCORS
public class HappyCurriculumController extends Controller {
	
    @Inject
    HappyCurriculumService service;
    
    
    /**
     * 课程类型列表
     */
    @ApiOper("课程类型列表")
    @Authority(description = "课程类型列表", permission = "admin:aHappy:getCurriculumMod", permissionParentName = "课程模块", permissionName = "课程管理", type = 1)
    public void getCurriculumMod()throws Exception{
    	Ret ret = service.getCurriculumMod();
    	renderJson(ret);
    }
    
    @ApiOper("移动课程类型")
    @Authority(description = "移动课程类型", permission = "admin:aHappy:moveCurriculumMod", permissionParentName = "课程模块", permissionName = "课程管理", type = 2)
    public void moveCurriculumMod(
    		@NotEmpty @Size(min=0) @ApiPara(value = "curriculumModId",notes = "类型id") Integer curriculumModId, 
    		@NotEmpty @Size(min=1, max=2) @ApiPara(value = "direction",notes = "移动方向(1向上,2向下)") Integer direction) throws Exception{
    	Ret ret = service.moveCurriculumMod(curriculumModId, direction);
    	renderJson(ret);
    } 
    
    /**
     * 添加课程类型
     */
    @ApiOper("添加课程类型")
    @Authority(description = "添加课程类型", permission = "admin:aHappy:addCurriculumMod", permissionParentName = "课程模块", permissionName = "课程管理", type = 2)
    public void addCurriculumMod(
    		@NotBlank @Size(min=0,max=16) @ApiPara(value = "name",notes = "名称") String name,
    		@ApiPara(value = "icon",notes = "图标") String icon,
    		@ApiPara(value = "parentId",notes = "父级id") Integer parentId) throws Exception{
    	Integer userId = getAttr("userId");
    	Ret ret = service.addCurriculumMod(userId, name, icon, parentId);
    	renderJson(ret);
    }
    
    /**
     * 修改课程类型
     */
    @ApiOper("修改课程类型")
    @Authority(description = "修改课程类型", permission = "admin:aHappy:changeCurriculumMod", permissionParentName = "课程模块", permissionName = "课程管理", type = 2)
    public void changeCurriculumMod(
    		@NotEmpty @Size(min=0) @ApiPara(value = "curriculumModId",notes = "类型id") Integer curriculumModId,
    		@Size(min=0,max=16) @ApiPara(value = "name",notes = "名称") String name,
    		@ApiPara(value = "icon",notes = "图标") String icon,
    		@ApiPara(value = "parentId",notes = "父级id") Integer parentId) throws Exception{
    	Integer userId = getAttr("userId");
    	Ret ret = service.changeCurriculumMod(userId, curriculumModId, name, icon, parentId);
    	renderJson(ret);
    }
    
    /**
     * 删除课程类型
     */
    @ApiOper("删除课程类型(删除后的迁移，指的是小类迁移，不是课程迁移)")
    @Authority(description = "删除课程类型", permission = "admin:aHappy:deleCurriculumMod", permissionParentName = "课程模块", permissionName = "课程管理", type = 2)
    public void deleCurriculumMod(
    		@NotEmpty @Size(min=0) @ApiPara(value = "curriculumModId",notes = "类型id") Integer curriculumModId,
    		@Size(min=0) @ApiPara(value = "curriculumModId",notes = "转移到的类型id") Integer toCurriculumModId) throws Exception{
    	Integer userId = getAttr("userId");
    	Ret ret = service.deleCurriculumMod(userId, curriculumModId, toCurriculumModId);
    	renderJson(ret);
    }
    
    /**
     * 删除课程
     */
    @ApiOper("删除课程")
    @Authority(description = "删除课程", permission = "admin:aHappy:deleCurriculum", permissionParentName = "课程模块", permissionName = "课程管理", type = 2)
    public void deleCurriculum(@NotEmpty @Size(min=0) @ApiPara(value = "curriculumId", notes = "课程id") Integer curriculumId) throws Exception{
    	Integer userId = getAttr("userId");
    	Ret ret = service.deleCurriculum(userId, curriculumId);
    	renderJson(ret);
    }
    
    /**
     * 查询课列表（其中观看次数是课程下所有视频观看的次数）
     */
    @ApiOper("查询课列表")
    @Authority(description = "查询课列表", permission = "admin:aHappy:getCurriculumList", permissionParentName = "课程模块", permissionName = "课程管理", type = 1)
    public void getCurriculumList(
    		@ApiPara(value = "curriculumName",notes = "课程名称")String curriculumName,
    		@ApiPara(value = "lecturerName",notes = "授课人名称")String lecturerName,
    		@ApiPara(value = "curriculumId",notes = "课程id")Integer curriculumId,
    		@NotEmpty @Size(min=0) @ApiPara(value = "page",notes = "当前页")Integer page,
    		@NotEmpty @Size(min=0) @ApiPara(value = "limit",notes = "每页大小")Integer limit) throws Exception{
    	Integer userId = getAttr("userId");
    	Ret ret = service.getCurriculumList(userId, lecturerName, curriculumName, curriculumId, page, limit);
    	renderJson(ret);
    }
    
    /**
     * 设置课程是否公开
     */
    @ApiOper("设置课程是否公开")
    @Authority(description = "设置课程是否公开", permission = "admin:aHappy:setPublic", permissionParentName = "课程模块", permissionName = "课程管理", type = 2)
    public void setPublic(@NotEmpty @Size(min=0) @ApiPara(value = "curriculumId", notes = "课程id") Integer curriculumId) throws Exception{
    	Integer userId = getAttr("userId");
    	Ret ret = service.setPublic(userId, curriculumId);
    	renderJson(ret);
    }
    
    /**
     * 设置课程是否推荐
     */
    @ApiOper("设置课程是否推荐")
    @Authority(description = "设置课程是否推荐", permission = "admin:aHappy:setGood", permissionParentName = "课程模块", permissionName = "课程管理", type = 2)
    public void setGood(@NotEmpty @Size(min=0) @ApiPara(value = "curriculumId", notes = "课程id") Integer curriculumId) throws Exception{
    	Integer userId = getAttr("userId");
    	Ret ret = service.setGood(userId, curriculumId);
    	renderJson(ret);
    }
    
    /**
     * 查询课程互动数据
     */
    @ApiOper("查询课程互动数据")
    @Authority(description = "查询课程互动数据", permission = "admin:aHappy:getUserInteraction", permissionParentName = "课程模块", permissionName = "课程管理", type = 1)
    public void getUserInteraction(
    		@NotEmpty @Size(min=0) @ApiPara(value = "curriculumId", notes = "课程id") Integer curriculumId,
    		@NotEmpty @Size(min=0) @ApiPara(value = "page",notes = "当前页")Integer page,
    		@NotEmpty @Size(min=0) @ApiPara(value = "limit",notes = "每页大小")Integer limit) throws Exception{
    	Ret ret = service.getUserInteraction(curriculumId, page, limit);
    	renderJson(ret);
    }
    
    
    
    
    
    
}
